package com.selen.controller.test;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.Data;
import org.springframework.web.bind.annotation.*;

import java.io.Serializable;
import java.util.Map;

/**
 * @author Selen
 */
@Tag(name = "PigController", description = "猪的控制器")
@RestController
public class SpringDocController {

    @Operation(summary = "分页查询猪", description = "用于分页查询猪的控制方法")
    @GetMapping("/test/springDoc/page")
    public Object page(@RequestParam @Parameter(description = "显示第几页") Integer pageNum,
                       @RequestParam @Parameter(description = "每页多少条") Integer pageSize) {
        return Map.of("参数pageNum", pageNum, "参数pageSize", pageSize);
    }

    @Operation(summary = "查询一只猪", description = "用于查询一只猪的控制方法")
    @GetMapping("/test/springDoc/selectById/{id}")
    public Object selectById(@PathVariable @Parameter(description = "猪的主键") Long id) {
        return Map.of("参数id", id);
    }

    @Operation(summary = "添加一只猪", description = "用于添加一只猪的控制方法")
    @PostMapping("/test/springDoc/insert")
    public Object insert(@RequestBody PigDTO pigDTO) {
        return Map.of("参数pigName", pigDTO.getName());
    }

    @Schema(name = "猪的DTO实体", description = "猪的DTO实体，包含猪表的全部可操作属性")
    @Data
    public static class PigDTO implements Serializable {

        @Schema(description = "猪的名字", required = true, example = "佩奇")
        private String name;
    }

}
